﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;

namespace CustomerAssistant
{
    /// <summary>
    /// TrayMenu.xaml 的交互逻辑
    /// </summary>
    public partial class TrayMenu : UserControl
    {
        public TrayMenu()
        {
            InitializeComponent();
            var funcList = new List<object>()
            {
                new {
                    Name="订单通知",
                    Callback=new Action(()=>{
                        TrayNotifyUtil.StopFlashTrayIcon();
                        OrderMonitor.Notice();
                        TrayNotifyUtil.CloseTrayMenu();
                    }),
                },
                new {
                    Name="退出",
                    Callback=new Action(()=>{
                    Application.Current.Shutdown();
                    }),
                },
            };
            listbox1.Height = Height = funcList.Count * 25;
            listbox1.Width = Width;
            listbox1.ItemsSource = funcList;
            listbox1.SelectionChanged += new SelectionChangedEventHandler(listbox1_SelectionChanged);
        }

        private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            var lb = sender as ListBox;
            if (lb != null)
            {
                var item = lb.SelectedItems[0];
                ((Action)ProInfo.GetPropertyValue(item, "Callback"))();
            }
        }

        public class ProInfo
        {
            public static Object GetPropertyValue(object O, string P)
            {
                return O.GetType().GetProperty(P).GetValue(O, null);
            }
        }
    }
}